# 外部档案初始化，将第一pareto前沿中的狮王添加到archive中
import config


def init_archive(schemesList, paretofrontiers, init_RTmatrix_filled):
    best_fitness = paretofrontiers[0][0]
    best_lion = schemesList[best_fitness[0]]
    best_RTmatrix = init_RTmatrix_filled[best_fitness[0]]
    return best_lion, best_fitness, best_RTmatrix


def select_global_best(copy_schemesList, lion_g, lion_fitness, newParetofrontiers, update_RTmatrix, RTlion_g):
    best_fitness = newParetofrontiers[0][0]
    best_lion = copy_schemesList[best_fitness[0]]
    best_RTlion_g = update_RTmatrix[best_fitness[0]]
    if best_fitness[1] < lion_fitness[1] and best_fitness[2] < lion_fitness[2] and best_fitness[3] < lion_fitness[3]:
        return best_lion, best_fitness, best_RTlion_g
    elif best_fitness[1] > lion_fitness[1] and best_fitness[2] > lion_fitness[2] and best_fitness[3] > lion_fitness[3]:
        return lion_g, lion_fitness, RTlion_g
    else:
        fitness_g_his = lion_fitness[1] * config.s_t_weight + lion_fitness[2] * config.r_weight + lion_fitness[
            3] * config.s_t_dis_weight
        fitness_g_cur = best_fitness[1] * config.s_t_weight + best_fitness[2] * config.r_weight + best_fitness[
            3] * config.s_t_dis_weight
        if fitness_g_his < fitness_g_cur:
            return lion_g, lion_fitness, RTlion_g
        else:
            return best_lion, best_fitness, best_RTlion_g
